{% extends "base.html" %}
{% block header %}
<script type="text/javascript" src="/static/js/jquery.treeview.js"></script>
<script type="text/javascript" src="/static/js/jquery.cookie.js"></script>
<script type="text/javascript">
	function startMonitor(){
		$.get("/monitor/monitorstatus/", {'do':'start'},function(data){
			  alert("Data Loaded: " + data);
			});
	}

	function stopMonitor(){
		$.get("/monitor/monitorstatus/", {'do':'stop'},function(data){
			  alert("Data Loaded: " + data);
			});
	}

	function initBind1(){
		$('#stop').bind('click', function (){ stopMonitor()});
	}

	function initBind2(){
		$('#start').bind('click', function (){ startMonitor()});
	}
	
	$(document).ready(function(){
		//$("#browser").html("<li><span class='folder'>test1</span></li>");
		initBind1();
		initBind2();
		$(".tabs > ul").tabs();
	    $("#browser").treeview({
            collapsed:true,
            persist: "cookie",
			toggle: function() {
				console.log("%s was toggled.", $(this).find(">span").text());
			}
		});
	});
</script>

{% endblock %}

{% block menu %}
   {% include 'monitor-menu.html' %}
{% endblock %}

{% block aside %}
<div class='left-col'>
{% autoescape off %}
    {{ tree }}
{% endautoescape %}
</div>

{% endblock %}

{% block content %}
        <div id="mon-tit">
            <div class="left">暴风服务监控 >> 所有监控项目</div>
            {% if id %}
            <div class="right"><a href="/monitor/addmonitor/?id={{id}}">添加监控</a></div>
            {% else %}
            <div class="right"><a href="/monitor/addmonitor/">添加监控</a></div>
            {% endif %}
        </div>
        <div class="clr"></div>
        <hr>
        <h3 class='tit'>监控列表
            <span > 
                <a  href="/monitor/">所有</a>|
                <a  style="color:black" href="/monitor/errorlist">错误</a>
            </span>
        </h3>
       
        <div id="f">
			<form method="post" action="/monitor/">
				过滤：<input type="text" name="query" size="30" maxlength=255 style="width:900px">&nbsp;
				<input type="submit" value="查询"/>&nbsp;
			</form>
        </div>

            {% if flag == "open" %}
				<a href="/monitor/export">导出搜索结果到CSV</a>
			{% endif %}
        <div id="mon-dis" class="right-col">
            <div class="title">
				<!--
				<span style="width:10%">选择</span>
				-->
				<span style="width:25%">监控名称</span>
				<span style="width:25%">URL</span>
				<span style="width:10%">监控类型</span>
				<span style="width:10%">监控频率</span>
				<span style="width:10%">可用率</span>
				<span style="width:20%">操作</span>
            </div>
	{% if messages %}
		{% for message in messages %}
			{% if message == "modifysuccess" %}
				<script language=javascript>alert('修改监控信息成功!!');window.location.href='/monitor';</script>
			{% endif %}
			{% if message == "null" %}
				<h3>查询失败或无结果</h3>
			{% endif %}
		{% endfor %}
	{% endif %}
		{% for l in lst %}
			<div class="{% cycle 'ji' 'ou' %}" >
				<!--
                <span style="width:10%"><input type="checkbox" />{{ forloop.counter }}</span>
                -->
                <span style="width:25%"><a href="/monitor/monitorview/{{ l.id }}">{{ l.mname }}</a></span>
                <span style="width:25%">{{ l.url }}</span>
                <span style="width:10%">{{ l.tpl }}</span>
                <span style="width:10%">{{ l.freq }}</span>
                {% if l.status == "0" %}
                <span style="width:10%;color:red">{{ l.available }}</span>
                {% else %}
                <span style="width:10%">{{ l.available }}</span>
                {% endif %}
                <span style="width:20%">
                {% ifequal l.open '1' %}
                <a href="/monitor/monitorstatus/{{ l.id }}?do=stop" >暂停</a>|
                {% endifequal  %}
                {% ifequal l.open '0' %}
                <a href="/monitor/monitorstatus/{{ l.id }}?do=start" >开始</a>|
                {% endifequal  %}
                <a href="/monitor/modifymonprj/{{ l.id }}"> 修改 </a>|
                <a href="/monitor/deletemonprj/{{ l.id }}" onclick="if(confirm('确定删除监控么？')){}else{return false;};"> 删除</a></span>
            </div>

		{% endfor %}
        </div>
        <div class='clr'></div>
        <div class='page'>
		{% for p in page_lst %}
            {% if p == page %}
            <a class='on' href='/monitor?page={{p}}'>{{p}}</a>
            {%else%}
            <a href='/monitor?page={{p}}'>{{p}}</a>
            {% endif %}
        {% endfor %}    

        </div>
{% endblock %}
